 using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using CrystalCore.Mapping;

namespace CrystalCore
{
    public static class Resources
    {
        //Collections        
        public static Dictionary<string, Effect> FxLibaray;
        public static Dictionary<string, SpriteFont> Fonts;
        public static Dictionary<ColourCode, Color> Colours;
        
        //UV Textures
        public static Texture2D CubeWallTexture { get; private set; }
        public static Texture2D CubeFloorTexture { get; private set; }
        public static Texture2D CubeGateTexture { get; private set; }

        //Models
        public static Model CubeWallModel { get; private set; }        
        public static Model CubeFloorModel { get; private set; }
        public static Model CubeGateModel { get; private set; }
        public static Model ElementalBaseModel { get; private set; }

        //Loading        
        public static void LoadData(Game game)
        {
            //Load in the Effects
            FxLibaray= new Dictionary<string, Effect>();
            FxLibaray.Add("CellFx", game.Content.Load<Effect>("gfx/CellFx"));
            FxLibaray.Add("ElementalFx", game.Content.Load<Effect>("gfx/actorfx"));

            //Fonts
            Fonts = new Dictionary<string, SpriteFont>();
            Fonts.Add("default", game.Content.Load<SpriteFont>("default"));
            Fonts.Add("menu", game.Content.Load<SpriteFont>("fonts/menu"));

            //Colours
            Colours = new Dictionary<ColourCode, Color>();
            Colours.Add(ColourCode.Blue, new Color(0, 74, 127));
            Colours.Add(ColourCode.White, new Color(216,255,255));
            Colours.Add(ColourCode.Red, new Color(211, 0, 0));
            Colours.Add(ColourCode.Brown, new Color(124, 73, 38));

            //Load in Textures
            CubeWallModel = LoadModel(game, FxLibaray["CellFx"], "assets/$cube_wall");
            CubeWallTexture = game.Content.Load<Texture2D>("graphics/uv/$cube_wall");            

            CubeFloorModel = LoadModel(game, FxLibaray["CellFx"], "assets/$cube_floor_1_3");
            CubeFloorTexture = game.Content.Load<Texture2D>("graphics/uv/$cube_floor_1_3");

            CubeGateModel = LoadModel(game, FxLibaray["CellFx"], "assets/$cube_part_gate");
            CubeGateTexture = game.Content.Load<Texture2D>("graphics/uv/$cube_part_gate");

            ElementalBaseModel = LoadModel(game, FxLibaray["ElementalFx"], @"assets/$Elemental_base");
        }

        public static Model LoadModel(Game game, Effect fx, string assetName)
        {
            Model newModel = game.Content.Load<Model>(assetName);

            foreach (ModelMesh mesh in newModel.Meshes)
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    meshPart.Effect = fx.Clone();

            return newModel;
        }
    }
}